package com.example.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaohei.crm.common.result.Result;
import com.xiaohei.crm.dao.Region;
import com.xiaohei.crm.service.RegionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequiredArgsConstructor
public class RegionController {

    private final RegionService regionService;

    /**
     * 分页查询区域信息
     * @return
     */
    @GetMapping("/region/findByPage")
    public Result<IPage> findByPage(Integer pageIndex, Integer pageSize, String area){
        return regionService.findByPage(pageIndex, pageSize, area);
    }

    /**
     * 添加区域
     * @param region   请求参数
     * @return
     */
    @PostMapping("/region")
    public Result save(@RequestBody Region region){
        regionService.saveRegion(region);
        return Result.ok();
    }

    /**
     * 修改区域信息
     * @param region
     * @return
     */
    @PutMapping("/region")
    public Result update(@RequestBody Region region){
        regionService.updateRegionById(region);
        return Result.ok();
    }

    /**
     * 逻辑删除区域
     * @param
     * @return
     */
    @DeleteMapping("region/{id}")
    public Result<String> deleteByUsername(@PathVariable("id") String id){
        regionService.removeByRegionId(id);
        return Result.ok();
    }

}
